package com.example.springinitialization.exception;

import com.example.springinitialization.response.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MyException.class)
    public Result handleException(MyException myException) {
        return Result.fail(myException.getCode(), myException.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public Result handleException(RuntimeException runtimeException) {
        return Result.fail(runtimeException.getMessage());
    }
}
